package org.jpro.common.bean;

import static javax.persistence.GenerationType.IDENTITY;

import java.io.Serializable;
import java.sql.Timestamp;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * <P>功能描述 : 所有映射实体都要集成本类 </P>
 * <P>File name : BaseEntity </P>
 * <P>Author : 王泽浩 </P>
 * <P>E-Mail : 1028625100@qq.com </P>
 * <P>Date : 2017/1/1 下午8:20</P>
 */
@Getter
@Setter
@MappedSuperclass
@NoArgsConstructor
@AllArgsConstructor
public class BaseEntity<ID extends Serializable> implements java.io.Serializable {

    /**
     * 是否删除 否
     */
    public static final char DEL_FLAG_FALSE = 0;

    /**
     * 是否删除 是
     */
    public static final char DEL_FLAG_TRUE = 1;

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "id", unique = true, nullable = false)
    private ID id;

    /**
     * 创建者
     */
    @Column(name = "create_by")
    private String createBy;

    /**
     * 创建时间
     */
    @Column(name = "create_date")
    private Timestamp createDate;

    /**
     * 更新者
     */
    @Column(name = "update_by")
    private String updateBy;

    /**
     * 更新时间
     */
    @Column(name = "update_date")
    private Timestamp updateDate;

    @Column(name = "del_flag")
    private char delFlag = DEL_FLAG_FALSE;

    public BaseEntity(ID id) {
        this.id = id;
    }

    public void del() {
        this.setDelFlag(DEL_FLAG_TRUE);
    }
}
